package com.zlcx.tz.live.domain.backup;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zlcx.tz.live.domain.TimeLearnRoomUsersDO;
import lombok.Builder;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author anjl
 * 计时学习自习室所有用户进入和退出信息
 */

@Data
@Builder
@Entity(name = "tz_time_learn_room_users_backup")
@JsonSerialize
@DynamicUpdate
@DynamicInsert
public class TimeLearnRoomUsersBackUpDO implements Serializable {


    private static final long serialVersionUID = -6392967729759283530L;
    @Id
    @GeneratedValue
    private Long id;

    /**
     * 关联id TimeLearnRoomUsersDO.id
     */
    private Long relationId;

    /**
     * 房间id
     */
    private Long roomId;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 进入房间时间
     */
    private Date joinTime;

    /**
     * 退出房间时间
     */
    private Date quitTime;

    /**
     * 用户状态
     */
    private String state;

    /**
     * 学习内容
     */
    private String studyContent;

    private Date createTime;

    private Date updateTime;

    public static TimeLearnRoomUsersBackUpDO from(TimeLearnRoomUsersDO roomUser) {
        return Objects.isNull(roomUser) ? null : TimeLearnRoomUsersBackUpDO
                .builder()
                .relationId(roomUser.getId())
                .joinTime(roomUser.getJoinTime())
                .quitTime(new Date())
                .roomId(roomUser.getRoomId())
                .userId(roomUser.getUserId())
                .state(roomUser.getState())
                .createTime(roomUser.getCreateTime())
                .updateTime(roomUser.getUpdateTime())
                .build();

    }
}